/*
Copyright 2008  Four Roads LLC conact@4-roads.com

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either 
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
using System.Web.Caching;
using System.Xml;
using System.Xml.Serialization;
using CommunityServer.Components;
using CommunityServer.Configuration;

namespace FourRoads.Links.Controls
{
	/// <summary>
	/// Summary description for ResourceLinkConfiguration.
	/// </summary>
	[Serializable(),
	XmlRoot("ResourceLinks")]
	public class ResourceLinkConfiguration
	{
		public ResourceLinkConfiguration()
		{

		}

		public static ResourceLinkConfiguration Instance()
		{
			string cacheKey = "ResourceLinkConfiguration";
			ResourceLinkConfiguration config = CSCache.Get(cacheKey) as ResourceLinkConfiguration;

			if(config == null)
			{
				XmlNode node = CSConfiguration.GetConfig().GetConfigSection("CommunityServer/ResourceLinks");

				if(node != null)
				{
					XmlSerializer serializer = new XmlSerializer(typeof(ResourceLinkConfiguration));

					XmlNodeReader  reader = new XmlNodeReader(node);
	
					config = serializer.Deserialize(reader) as ResourceLinkConfiguration;

					CSCache.Insert(cacheKey , config);
				}
			}

			return config;
		}
	
		[XmlAttribute("LinkEnabledImage")]
		public string LinkEnabledImage = string.Empty;

		[XmlAttribute("LinkDisabledImage")]
		public string LinkDisabledImage = string.Empty;
	}
}
